import matplotlib.pyplot as plt
import pandas as pd

import numpy as np

labels = ['FoV_inside','FoV_outside','FoV_adjacency']
# BOLA = []
# LB = []
# HB = []
# DP = []
# Proposal = []

BOLA = [1.01264429023768,	1.01267645995693,	1.01285013786367]
LB = [0.333333333333333,	0.333333333333333,	0.333333333333333]
HB = [1.33333333333333,	1.33333333333333,	1.33333333333333]
DP = [0.702779825079603,	0.829710836348918,	0.720509664009769]
Proposal = [1.00699599998949,	0.992073406735989,	0.994503113285944]

# plt.rcParams['font.family'] = ['Times New Roman']
plt.rcParams['font.family'] = ['Arial']
plt.xticks(fontsize=16)
plt.yticks(fontsize=16)
# 设置坐标标签字体大小
# ax.set_xlabel(..., fontsize=20)
# ax.set_ylabel(..., fontsize=20)
# # 设置图例字体大小
# ax.legend(..., fontsize=20)
# 选择如何显示刻度
# ax.xaxis.set_ticks_position(‘none’)
# ax.yaxis.set_ticks_position(‘right’)

fig, ax = plt.subplots(1, 1, figsize=(4, 2.472))
# fig, ax = plt.figure(figsize=(8, 4.944))

x = np.arange(len(labels))
width = 0.15  # 每根柱子宽度

# label_font = {
#     'weight': 'bold',
#     'size': 16,
#     'family': 'simsun'
# }

# tick_params参数刻度线样式设置
# ax.tick_params(axis=‘x’, tickdir=‘in’, labelrotation=20)参数详解
# axis : 可选{‘x’, ‘y’, ‘both’} ，选择对哪个轴操作，默认是’both’
# which : 可选{‘major’, ‘minor’, ‘both’} 选择对主or副坐标轴进行操作
# direction/tickdir : 可选{‘in’, ‘out’, ‘inout’}刻度线的方向
# color : 刻度线的颜色，我一般用16进制字符串表示，eg：’#EE6363’
# width : float, 刻度线的宽度
# size/length : float, 刻度线的长度
# pad : float, 刻度线与刻度值之间的距离
# labelsize : float/str, 刻度值字体大小
# labelcolor : 刻度值颜色
# colors : 同时设置刻度线和刻度值的颜色
# bottom, top, left, right : bool, 分别表示上下左右四边，是否显示刻度线，True为显示
ax.tick_params(which='major', direction='in', length=5, width=1.5, labelsize=11, bottom=False)
# labelrotation=0 标签倾斜角度
ax.tick_params(axis='x', labelsize=11, bottom=False, labelrotation=0)

ax.set_xticks(x)
# ax.set_ylim(ymin=0, ymax=40)
# 0 - 1800 ，200为一个间距
# ax.set_yticks(np.arange(0, 41, 10))
# ax.set_ylabel('Bitrate', fontdict=label_font)
ax.set_ylabel('Bitrate')
ax.set_xticklabels(labels)
# ax.legend(markerscale=10,fontsize=12,prop=legend_font)
ax.legend(markerscale=10, fontsize=6)

'''
# 设置有边框和头部边框颜色为空right、top、bottom、left
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
'''

# 上下左右边框线宽
linewidth = 0.5
for spine in ['top', 'bottom', 'left', 'right']:
    ax.spines[spine].set_linewidth(linewidth)

    # Add some text for labels, title and custom x-axis tick labels, etc.


def autolabel(rects):
    for rect in rects:
        height = rect.get_height()
        ax.annotate('{}'.format(height),
                    xy=(rect.get_x() + rect.get_width() / 2, height),
                    xytext=(0, 3),  # 3 points vertical offset
                    textcoords="offset points",
                    ha='center', va='bottom')

# hatch 	{'/', '\', '|', '-', '+', 'x', 'o', 'O', '.', '*'}
# linestyle {'-', '--', '-.', ':', '', (offset, on-off-seq), ...}
rects1 = ax.bar(x - width*12/5, BOLA, width, label='Student',edgecolor='lightgoldenrodyellow',color='#000e4d',linewidth=.8,
               hatch='x')
rects2 = ax.bar(x - width*6/5, HB, width, label='Teacher',ec='#FAEBD7',color='#5c095e',
                lw=.8,hatch='o')
rects3 = ax.bar(x, LB, width, label='Student',edgecolor='g',color='#9f055e',linewidth=.8,
               hatch='/')
rects4 = ax.bar(x + width*6/5, DP, width, label='Teacher',ec='k',color='#d5314f',
                lw=.8,hatch='+')
rects5 = ax.bar(x + width*12/5, Proposal, width, label='Teacher',ec='k',color='#f66934',
                lw=.8,hatch='\\')

l1 = plt.legend([rects1,rects2,rects3,rects4,rects5],['BOLA','HB','LB','DP','Proposal'],loc = "best", fontsize="8",
                ncol=3)

# autolabel(rects1)
# autolabel(rects2)
fig.tight_layout()

plt.savefig('./bitrate_fov.jpg',dpi=400,bbox_inches = 'tight')
#plt.savefig(r'C:\Users\admin\Pictures\Camera Roll\exam_annotate1.jpg',
#            dpi=400,bbox_inches = 'tight')

plt.show()
